<?php
namespace frontend\controllers;

use frontend\models\Information;
use common\components\FrontBaseController;
use Yii;
use common\helps\tools;
use common\helps\code;
/**
 * Team controller
 */
class InfoController extends FrontBaseController
{

    public $modelClass = 'common\models\Information';
    public function init()
    {
        parent::init();
    }

    /**
     * 获取列表
     * @author cpy(1442435897@qq.com)
     * @return json
     */
    public  function  actionGetList(){
        $request =$this->request;
        $model = new Information();
        $params = $request->queryParams;
        $total_data = $model->getList($params);
        $data = tools::getPageData($total_data,empty($params['page_size'])?'':$params['page_size'],empty($params['page'])?'':$params['page']);
        foreach($data['data'] as $k => $value){
            if($value['section'] == 1){
                $row = '行业新闻';
            }else{
                $row = '企业公告';
            }
            $data['data'][$k]['section'] = $row;
        }
        return code::success($data);
    }

    /**
     * 详情
     * @author cpy(1442435897@qq.com)
     * @return json
     */
    public  function  actionDetail(){
        $request =$this->request;
        $params = $request->bodyParams;
        $model = new Information();

        if(empty($params['id']))
            return code::error('mistake');
        $res['detail'] = $model::findOne(['id' => $params['id']]);
        $res['detail']['created_at'] = date('Y-m-d H:i:s',$res['detail']['created_at']);
        $res['list'] = $model->getLimitList(['section' => $res['detail']['section']]);
        return code::success($res);
    }



}

